﻿using System.IO;
using System.Windows;
using System.Windows.Controls;
using VupSlashLauncher.Common;
using VupSlashLauncher.Model;

namespace VupSlashLauncher.View
{
    /// <summary>
    /// GameDownloadView.xaml 的交互逻辑
    /// </summary>
    public partial class GameInstallView : System.Windows.Controls.UserControl
    {

        public GameInstallView()
        {
            InitializeComponent();
        }
        private void FirstButton_Click(object sender, RoutedEventArgs e)
        {
            ChageView(FirstGrid);
        }
        private void SecondButton_Click(object sender, RoutedEventArgs e)
        {
            SecondButton.IsEnabled = true;
            SecondPath.Opacity = 1;
            if (DirectoryLabel.Text == "" || DirectoryLabel.Text == "请输入或选择路径") GlobalValues.GameDir = @".\VupSlash";
            else GlobalValues.GameDir = DirectoryLabel.Text;
            INIOperation.INIWriteValue(GlobalValues.ConfigFile, "Vup", "GameDirectory", GlobalValues.GameDir);
            if (!Directory.Exists(GlobalValues.GameDir)) Directory.CreateDirectory(GlobalValues.GameDir);
            ChageView(SecondGrid);
        }
        private void ThirdButton_Click(object sender, RoutedEventArgs e)
        {
            ThirdButton.IsEnabled = true;
            ThirdPath.Opacity = 1;
            ChageView(ThirdGrid);
        }
        private void FourthButton_Click(object sender, RoutedEventArgs e)
        {
            FourthButton.IsEnabled = true;
            FourthPath.Opacity = 1;
            ChageView(FourthGrid);
        }
        private void FrontButton1_Click(object sender, RoutedEventArgs e)
        {
            try { System.Diagnostics.Process.Start(GlobalValues.GameDir + "\\font\\kill_font.ttf"); }
            catch { IMessageBox.Show("找不到字体文件！请先安装游戏", "读取错误", "好的"); }
        }
        private void FrontButton2_Click(object sender, RoutedEventArgs e)
        {
            try { System.Diagnostics.Process.Start(GlobalValues.GameDir + "\\font\\simli.ttf"); }
            catch { IMessageBox.Show("找不到字体文件！请先安装游戏", "读取错误", "好的"); }
        }
        private void ChageView(Grid grid)
        {
            if (grid != FirstGrid)
            {
                if (FirstGrid.Visibility == Visibility.Visible) IAnimation.Disappear(FirstGrid, new Point(-10, 0));
            }
            if (grid != SecondGrid)
            {
                if (SecondGrid.Visibility == Visibility.Visible) IAnimation.Disappear(SecondGrid, new Point(-10, 0));
            }
            if (grid != ThirdGrid)
            {
                if (ThirdGrid.Visibility == Visibility.Visible) IAnimation.Disappear(ThirdGrid, new Point(-10, 0));
            }
            if (grid != FourthGrid)
            {
                if (FourthGrid.Visibility == Visibility.Visible) IAnimation.Disappear(FourthGrid, new Point(-10, 0));
            }

            if (grid == FirstGrid)
            {
                if (FirstButton.IsChecked == false) FirstButton.IsChecked = true;
            }
            else if (grid == SecondGrid)
            {
                if (SecondButton.IsChecked == false) SecondButton.IsChecked = true;
            }
            else if (grid == ThirdGrid)
            {
                if (ThirdButton.IsChecked == false) ThirdButton.IsChecked = true;
            }
            else if (grid == FourthGrid)
            {
                if (FourthButton.IsChecked == false) FourthButton.IsChecked = true;
            }

            if (grid.Visibility == Visibility.Collapsed) IAnimation.Appear(grid, new Point(10, 0));
        }

    }
}
